//
//  FirstViewController.m
//  HomeFurnishing
//
//  Created by dllo on 16/4/7.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "FirstViewController.h"
#import "CaseTableViewCell.h"
#import "CaseBaseModel.h"
#import "DetailCaseVC.h"
@interface FirstViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)NSArray *dataArr;
@end

@implementation FirstViewController


-(void)dealloc
{
    [_tableV release];
    [_num release];
    [_dataArr release];
    [_name release];
    [super dealloc];
}
-(NSString *)segmentTitle
{
    
    NSString *str = [NSString stringWithFormat:@"%@ 案例",self.num];
    return str;
}
-(UIScrollView *)streachScrollView
{
    return self.tableV;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    self.dataArr = [NSArray array];
    self.tableV = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.rowHeight = 270;
    [self.view addSubview:self.tableV];
    [_tableV release];
    [self.tableV registerClass:[CaseTableViewCell class] forCellReuseIdentifier:@"FirstTableVCell"];
    [self dataHandle];
}

-(void)dataHandle
{
    
    
    NSString *str = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/user/%@/projects?start=0&count=10&user=木木",self.name];
    NSString *newStr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    [NetworkHandle GetDataWithURL:newStr dic:nil success:^(id responseObject) {
        self.dataArr = [CaseBaseModel transformWithArray:responseObject[@"projects"]];
        [self.tableV reloadData];
    } filed:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstTableVCell" forIndexPath:indexPath];
    CaseBaseModel *m = self.dataArr[indexPath.row];
    cell.title.text = m.title;
    cell.styleShow.text = m.styleShow;
    cell.typeShow.text = m.typeShow;
    cell.areaShow.text = [NSString stringWithFormat:@"%@平米",m.areaShow];
    cell.costShow.text = [NSString stringWithFormat:@"%@万元",m.cost];
    NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w750_h398_m0.jpg",m.coverPhoto];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str]];
    cell.mId = m.coverPhoto;
    [cell.userImgView sd_setImageWithURL:[NSURL URLWithString:m.large]];

    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailCaseVC *VC = [[DetailCaseVC alloc] init];
    VC.model = _dataArr[indexPath.row];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    [VC release];

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //NSLog(@"%f",scrollView.contentOffset.y);
    if (scrollView.contentOffset.y>=0 &&scrollView.contentOffset.y<=200-44) {
        //self.offsetBlock(scrollView.contentOffset.y);
        
        //self.tableV.scrollEnabled = NO;
        //self.tableV.scrollEnabled = NO;
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
